const express = require("express");
const app = express();
const auth = require("./middleware/auth");

app.use(function (req, res, next) {
    console.log("中间件一");
    next();
});

app.use(function (req, res, next) {
    console.log("中间件二");
    next();
});

app.get("/user", auth, (req, res) => {
    res.send({
        code: "200",
        data: {
            name: "张三",
            age: 18,
        },
    });
});

app.use("/error", (req, res) => {
    throw new Error("404 Not Found");
});

app.use((error, req, res, next) => {
    res.send("崩溃了" + error.message);
});

app.listen(3000, () => {
    console.log("Server is running on port 3000");
});
